package com.yanqu.road.server.cmd.grandchild.born;

import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.grandson.GrandChildModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_REFRESH_GRANDSON_TALENT_LIST,desc = "刷新孙子天赋列表")
public class RefreshGrandChildTalentListCmd extends AbstractCommand {
    private String id;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GrandChildProto.ReTalentReqMsg req = GrandChildProto.ReTalentReqMsg.parseFrom(packet.getBytes());
        id = req.getId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(GrandChildModule.class).refreshTalent(id);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GrandChildProto.ReTalentRespMsg.Builder resp = GrandChildProto.ReTalentRespMsg.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_REFRESH_GRANDSON_TALENT_LIST, resp);
        }
    }
}
